
package me.ak.sf;

import java.awt.Font;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.TrueTypeFont;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;


public class YouLooseState extends BasicGameState{

    @Override
    public int getID() {
        return 2;
    }
    
    public StateBasedGame parent;
    
    public TrueTypeFont looseFont = new TrueTypeFont(new Font("Arial",Font.PLAIN,50), true);
    public TrueTypeFont buttonFont = new TrueTypeFont(new Font("Arial",Font.PLAIN,35), true);
    
    public String buttonString = "Play Again.";
    public Rectangle buttonRect;

    @Override
    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
        buttonRect = new Rectangle(20,160, buttonFont.getWidth(buttonString), buttonFont.getHeight());
        
        parent = sbg;
    }

    @Override
    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
        g.setColor(new Color(255,255,255,currentAlpha));
        g.setFont(looseFont);
        g.drawString("You loose.", 20, 20);
        g.setFont(buttonFont);
        
        g.setColor(new Color(255,255,255,buttonAlpha));
        g.drawString(buttonString, 20, 160);
    }

    public float currentAlpha = 0;
    public float buttonAlpha = 0;
   
    
    @Override
    public void update(GameContainer gc, StateBasedGame sbg, int i) throws SlickException {
        if (currentAlpha < 1) {
            currentAlpha += 0.001f;
        }else {
            if (buttonAlpha < 1) {
                buttonAlpha += 0.002f;
            }
        }
    }
    
    @Override
    public void mousePressed(int button, int x, int y) {
        if (button==0) {
            if (buttonRect.contains(x, y)) {
                parent.enterState(0);
            }
        }
    }
    
    

}
